<?php

namespace app\admin\model\trades\assets;

use think\Model;


class Myaccount extends Model
{

    

    

    // 表名
    protected $table = 'activity_order';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'paytime_text',
        'createTime_text',
        'utime_text',
        'state_text',
    ];



    //绑定成功
    public function getStateList()
    {
        return ['1' => __('order_state 1'),'2' => __('order_state 2'),'3' => __('order_state 3'),'4' => __('order_state 4')];
    }


    //获取状态类型
    public function getStateTextAttr($value, $data)
    {
        $value = $value ? $value : $data['state'];
        $list = $this->getStateList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPaytimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['paytime']) ? $data['paytime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getCreatetimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['createTime']) ? $data['createTime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getUtimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['utime']) ? $data['utime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setPaytimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setCreatetimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setUtimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    /*
      * 头部活动标志
      *
      *
      */
    public function getHeadingList()
    {
        $ret = [
            0 => [
                'name' => 'trades/assets/myaccount/index',
                'head' => __('我的收入')
            ],
            1 => [
                'name' => 'trades/order/order/index',
                'head' => __("订单管理")
            ],
        ];
        return $ret;
    }

    public function activity()
    {
        return $this->belongsTo('app\admin\model\vactivities\Activity', 'activity_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
